<template>
<div style="width: 100%">
  <a-card class="card" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="准考证号">
              <a-input placeholder="请输入..." v-model="queryParam.ksbh"/>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="姓名">
              <a-input placeholder="请输入..." v-model="queryParam.ksxm"/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="招生年度">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zsnj">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="院系">
              <a-select :disabled="selectMenu.yx.length === 1" :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.bkyxsm" @change="yxChange">
                <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwh+"-"+ i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="专业">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.bkzydm" @change='zyChange'>
                <a-select-option v-for="i in selectMenu.zy" :key="i.id" :value="i.zyh">{{ i.zyh+'-'+i.zymc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="研究方向">
            <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.lqyjfxm">
            <a-select-option v-for="i in selectMenu.fx" :key="i.id" :value="i.yjfxm">{{ i.yjfxm.substring(i.yjfxm.length-2) +"-"+ i.yjfxmc }}</a-select-option>
            </a-select>
          </a-form-item>
              </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="学习形式">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zhxlxxxs">
                <a-select-option v-for="i in selectMenu.xxlx" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          </template>
          <a-col :sm="{span:20}" :xl="{span:10}">
             <span class="table-page-search-submitButtons" >
            <a-button type="primary" @click="loadData">查询</a-button>
            <a-button type="primary" @click="handleExport">导出</a-button>
            <a-button type="primary" @click="handleExportPDF">导出DBF</a-button>
            <!-- <a-button @click="queryParam = {};loadData()" >重置</a-button> -->
            <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
              </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
    <a-card class="card" :bordered="false">
      <a-alert :message="'总条数：' + pagination.total" type="info" show-icon />
      <a-table
        ref="table"
        size="default"
        rowKey="key"
        :columns="columns"
        :loading="loading"
          :dataSource="data"
        :pagination="pagination"
          @change="handleTableChange"
      >
        <template slot="ksbh" slot-scope="text,record">
          <a @click="handlePreview(record.id)">{{text}}</a>
        </template>
        <template slot="action" slot-scope="text,record">
            <a @click="handleReview(record)">变更导师</a>
        </template>
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
      </a-table>
    </a-card>
    <examinee :previewVisible="previewVisible" :info="examineeData" @close="handleClosePreview"></examinee>
    <!-- 审查 -->
    <query-review @close="handleReviewClose" @success="handleReviewSuccess" :planReviewVisible="planReviewVisible" :info="planReviewData"></query-review>
</div>
</template>

<script>
// import moment from 'moment'
import Examinee from '../../examinee/detail'
import QueryReview from './queryReview'
import { STable } from '~'
import { mapState } from 'vuex'

const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072']

export default {
  components: {
    STable,
    Examinee,
    QueryReview,
  },
  data () {
    return {
      advanced: true,
      previewVisible: false,
      fileList: [],
      uploading: false,
      loading: false,
      planReviewVisible: false,
      planReviewData: {},
      data: [],
      // 查询参数
      queryParam: {
        ksbh: '',
        ksxm:'',
        zhxlxxxs:'',
        bkyxsm:'',
        zsnj:'',
        bkzydm:''
      },
      postParams: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
         {
           title: '准考证号',
           dataIndex: 'ksbh',
           scopedSlots: { customRender: 'ksbh' },
           width:150
         },
         {
           title: '姓名',
           dataIndex: 'ksxm'
         },
         {
           title: '录取院系',
           dataIndex: 'bkyxsmc'
         },
         {
           title: '录取专业代码',
            dataIndex: 'lqzym'
         },
         {
           title: '录取专业',
           dataIndex: 'bkzymc'
         },

         {
           title: '研究方向',
           dataIndex: 'lqyjfxmc'
         },
         {
           title: '初试成绩',
           dataIndex: 'zf'
         },
         {
           title: '复试成绩',
           dataIndex: 'fscj'
         },
         {
           title: '综合评定',
           dataIndex: 'zhpd'
         },
         {
          title: '综合排名',
          dataIndex: 'zhpm'
        },
        {
          title: '档案是否转入',
          dataIndex: 'dasfzr'
        },
        {
          title: '培养模式',
          dataIndex: 'pymsm'
        },
        {
         title: '录取类别',
         dataIndex: 'lqlbm'
       },
       {
         title: '学制',
         dataIndex: 'xz'
       },
       {
         title: '录取导师',
         dataIndex: 'bkdsyxm'
       },
       {
         title: '录取状态',
         dataIndex: 'lqzt'
       },
       {
          title: '操作',
          dataIndex: 'cz',
          fixed: 'right',
          width: 120,
          scopedSlots: {
            customRender: 'action'
          }
        }
      ],
      recruitAddVisiable: false,
      recruitEditVisiable: false,
      selectMenu: {
        yx: [] ,// 院系
         zy:[] ,
        xxlx:[],
      },
      examineeData: {},
      pagination:{
       current:1,
        showSizeChanger: true,
       pageSizeOptions: ['10', '50', '100'],
          // 改变pageSize后触发
        onShowSizeChange: (current, pageSize) => this.pagination.pageSize = pageSize,
       showTotal: (() => {return `共 ${this.pagination.total} 条`})
      },
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    // 关闭弹层
      handleReviewClose() {
        this.planReviewVisible = false
      },
      // 保存
      handleReviewSuccess() {
        this.planReviewVisible = false
        this.$message.success('修改成功')
        this.loadData({
          pageSize: 10,
          pageNum: this.pagination.current
        })
      },
    // 变更导师
      handleReview(code) {
        console.log(code)
        this.planReviewData = code
        // this.$api.recruitstat.masterAdmissionManageId(code).then(res => {
        //   this.planReviewData = res.data
        // })
        this.planReviewVisible = true
      },
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
          // 获取学习形式
         this.$api.base.dictionaryData('TYPE0441').then(res => {
           this.selectMenu.xxlx = res.data
         })
         this.queryParam.bkyxsm  = res[0].data[0].dwh
         this.getProssion(this.queryParam.bkyxsm)
           // 获取当前学年
         this.$api.base.getSchoolYear().then(res=>{
           this.queryParam.zsnj = res.data.masterAdmissionYear
            this.loadData({
             pageSize: 10,
             pageNum: 1
           })
         })

      })
    },
    // 选择院系
   yxChange (code) {
     this.$set(this.queryParam, 'bkzydm ', '')
     this.$set(this.selectMenu, 'zy', [])
     if(code){
      this.getProssion(code)
     }
    },
    getProssion(code){
      this.$api.base.majorAll({lsdwh: code}).then(res => {
        this.$set(this.selectMenu, 'zy', res.data)
      })
    },
    //选择专业
    zyChange(code){
       this.$set(this.queryParam, 'lqyjfxm', '')
        this.$set(this.selectMenu, 'fx', [])
        if(code){
          this.getDurection(code)
        }
    },
    getDurection(code) {
        this.$api.base.searchDirectory({
          ssyxm: this.queryParam.bkyxsm,
          zsxn: this.queryParam.zsnj,
          sszym: code,
           xwccm: 2
        }).then(res => {
          this.$set(this.selectMenu, 'fx', res.data)
        })
      },
     // 加载数据
   loadData (parameter = {}) {
     if(!parameter.pageNum){
       this.pagination.current = 1
       parameter.pageNum = 1
     }
     let params = Object.assign(this.queryParam, parameter)
        this.loading = true;
       this.$api.recruitstat.admissionQueryList(params).then(res=>{
            const pagination = { ...this.pagination
          };
          pagination.total = 0
          if (res.data && res.data.total) {
            pagination.total = res.data.total;
          }
          this.data = []
          this.pagination = pagination;
          if (res.data && res.data.rows.length) {
            this.pagination.total = res.data.total
            this.data = res.data.rows;
          }
          this.loading = false;
       })
   },
   // 分页
   handleTableChange (pagination, filters, sorter) {
    console.log(pagination);
    const pager = { ...this.pagination };
    pager.current = pagination.current;
    this.pagination = pager;
    this.loadData({
      pageSize: pagination.pageSize,
      pageNum: pagination.current
    });
   },
      // 多选
   onSelectChange (selectedRowKeys,selectedRows) {
     console.log('selectedRowKeys changed: ', selectedRowKeys);
     this.selectedRows = selectedRows
     this.selectedRowKeys = selectedRowKeys
   },
    // 选择招生年度
    zsndChange () {

    },
    // 导出
    handleExport () {
      console.log('导出')
      this.$export('admissions/ssrqcx/export',this.queryParam)
    },
    // 导出PDF
    handleExportPDF () {
      console.log('导出PDF')
       this.$export('admissions/ssrqcx/dbfExport',this.queryParam)
    },
    // 查看考生消息资料
    handlePreviewInfo (code) {

    },
    // 查看考生详情
    handlePreview (code) {
      this.$api.recruitstat.masterAdmissionManageId(code).then( res=> {
         this.examineeData = res.data
          this.previewVisible = true
       })
    },
    // 关闭考生详情
    handleClosePreview () {
      this.previewVisible = false
    }
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
